package se.statemachine.fsm.mvcstyle.impl;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;

import se.statemachine.fsm.mvcstyle.View;

import java.awt.event.ActionListener;

public class ViewImpl extends JPanel implements View{
		
	private static final long serialVersionUID = -3475425870097659182L;

	private ActionListener listener;

	private JButton passSimulation;	
	private JButton coinSimulation;
	private JTextField state;
	
	public void initComponent(String passCommand, String coinCommand, String stateName){
		passSimulation = new JButton("pass simulation");
		coinSimulation = new JButton("coin simulation");
		state = new JTextField(stateName);		
		
		passSimulation.addActionListener(listener);
		passSimulation.setActionCommand(passCommand);
		coinSimulation.addActionListener(listener);
		coinSimulation.setActionCommand(coinCommand);
		
		add(passSimulation);
		add(coinSimulation);
		add(state);
	}
	
	public void setCurrentState(String currentState){
		state.setText(currentState);
	}
	
	public void update(){
		revalidate();
		repaint();
	}
	
	public void setActionListener(ActionListener listener){
		this.listener = listener; 
	}	
}
